﻿define([
    'Xjs/core/util',
    'Xjs/ui/Control',
    'Xjs/ui/Editor'
],
function (util, Control) {
    'use strict';

    var type = 'propertyRow',
    PropertyRow = Xjs.getType(type);

    if (PropertyRow) { // It has been already loaded
        return PropertyRow;
    }

    PropertyRow = util.define({
        base: Control,
        construct: function (conf, parent) {

            PropertyRow.base.constructor.call(this, conf, parent); // Call the base constructor

            // Create the label section
            this.createLabel(conf.label);

            // Create the editor section
            this.createEditor(conf.editor);
        },

        type: type,
        highlightable: true,
        selectable: true,
        createLabel: function (conf) {
            conf = conf || {};

            if (util.isString(conf)) {
                this.label = Xjs.create('content', {
                    content: conf,
                    attributes: {
                        cls: 'w-label'
                    }
                }, this);
            }
            else {
                this.label = Xjs.create(conf.type || 'control', conf, this);
                this.label.addClass('w-label');
            }

            this.addChild(this.label);
        },

        createEditor: function (conf) {

            conf = conf || {};

            util.augment(conf, {
                binder: conf.name
            });

            this.editor = Xjs.create(conf.type || 'control', conf, this);
            this.editor.addClass('w-editor');

            this.addChild(this.editor);
        }
    });

    Xjs.registerType(PropertyRow);

    return PropertyRow;
});